#importing all the required libraries
import pandas as pd
import numpy as np
import os
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib import style
np.random.seed(42)
from datetime import datetime, timedelta
%matplotlib inline
df = pd.read_csv('Sample store final.csv', error_bad_lines=False, engine='python')
df
df.columns = df.columns.to_series().apply(lambda x: x.strip())
df = df.copy()
df.head(5)
print(list(df.columns))
df.dtypes
sales_per_purchase_month = df.groupby(['Month_of_Order', 'Day_of_order'], as_index=False).Sales.sum()
sales_per_purchase_month = sales_per_purchase_month.sort_values(by=['Month_of_Order'], ascending=True)
Let's Take a Peep at Our Weekly and Monthly Sales Trend Over All The Four Consecutive Years In Our Historical Database
import plotly.express as px
salesdata = sales_per_purchase_month
fig = px.line(df, x="Month_of_Order", y="Sales", color='Day_of_order', title='Sales Each Month & Each DayofWeek')
fig.update_layout(
title="Sales Each Month & Each DayofWeek",
xaxis_title="Months",
yaxis_title="Sales(in $$)",
font=dict(
family="Courier New, monospace",
size=15,
color="#7f7f7f"
)
)
fig.show()
# creating an aggregation
avg_sales_per_category = df.groupby('CategoryName', as_index=False).agg({'Sales': ['count', 'mean']})
avg_sales_per_category.columns = ['Product Category', 'Total Sales', 'Average Sales']
avg_sales_per_category = avg_sales_per_category[avg_sales_per_category['Total Sales'] > 100]
avg_sales_per_category = avg_sales_per_category.sort_values(by='Total Sales', ascending=False)
avg_sales_per_category
Let's View Our Top Categories by Average Sales Made Over a Span of 4 Consecutive Years
import plotly.express as px
avg_sales = avg_sales_per_category[:20]
fig = px.bar(avg_sales, x='Product Category', y='Total Sales',
hover_data=['Average Sales'], color='Average Sales',
height=500)
fig.show()
# creating an aggregation
avg_profit_per_category = df.groupby('CategoryName', as_index=False).agg({'Profit': ['count', 'mean']})
avg_profit_per_category.columns = ['Product Category', 'Total Profit', 'Average Profit']
avg_profit_per_category = avg_profit_per_category[avg_profit_per_category['Total Profit'] > 100]
avg_profit_per_category = avg_profit_per_category.sort_values(by='Total Profit', ascending=False)
avg_profit_per_category
Top Categories by Average Profits Generated
import plotly.express as px
avg_profit = avg_profit_per_category[:20]
fig = px.bar(avg_profit, x='Product Category', y='Average Profit',
hover_data=['Total Profit'], color='Total Profit',
height=500)
fig.show()
# Keeping track of profits made using our knowledge of time
purchaseday = df.copy()
# creating an aggregation
profit_per_purchase_month = df.groupby(['Month_of_Order', 'Quarter_of_Year_for_Order', 'Day_of_order'], as_index=False).Profit.sum()
profit_per_purchase_month = profit_per_purchase_month.sort_values(by=['Month_of_Order'], ascending=True)
profit_per_purchase_month
# creating a purchase day feature alongside aggregration using our knowledge of time
sales_per_month = df.groupby(['Month_of_Order', 'Day_of_order','Quarter_of_Year_for_Order'], as_index=False).Sales.sum()
sales_per__month = sales_per_purchase_month.sort_values(by=['Month_of_Order'], ascending=True)
sales_per_month
# creating a purchase day feature
df = df.copy()
# creating an aggregation
sales_per_month = df.groupby(['Month_of_Order', 'Day_of_order'], as_index=False).Sales.mean()
sales_per_month
sales_per_month = sales_per_month.sort_values(by=['Day_of_order'], ascending=True)
sales_per_month
sales_per_category = df.groupby(['Month_of_Order', 'Product_Name'], as_index=False).Sales.sum()
sales_per_category = sales_per_category.sort_values(by=['Sales'], ascending=False)
sales_per_category.columns = ['Purchase Month','Product Category', 'Sales Revenue']
sales_per_category
import plotly.express as px
sales_per_category = df.groupby(['Month_of_Order', 'CategoryName'], as_index=False).Sales.sum()
sales_per_category = sales_per_category.sort_values(by=['Sales'], ascending=False)
sales_per_category.columns = ['Purchase_Month','CategoryName', 'Sales_Revenue']
sales_per_category
An Interactive and Insightful View of Our Top Categories by Sales Revenue
import plotly.express as px
df = sales_per_category
fig = px.bar(df, y='Sales_Revenue', x='CategoryName', text='Sales_Revenue', hover_data=['Purchase_Month'])
fig.update_traces(texttemplate='%{text:.2s}', textposition='outside')
fig.update_layout(barmode='stack',uniformtext_minsize=8, uniformtext_mode='hide')
fig.show()
df = pd.read_csv('Sample store final.csv', error_bad_lines=False, engine='python')
df
sales_per_category = df.groupby(['Month_of_Order', 'CategoryName'], as_index=False).Sales.sum()
sales_per_category = sales_per_category.sort_values(by=['Sales'], ascending=False)
sales_per_category.columns = ['Purchase_Month','CategoryName', 'Sales_Revenue']
sales_per_category
sales_per_category = df.groupby(['Month_of_Order', 'Product_Name'], as_index=False).Sales.sum()
sales_per_category = sales_per_category.sort_values(by=['Sales'], ascending=False)
sales_per_category.columns = ['Purchase_Month','Product_Name', 'Sales_Revenue']
sales_per_category
Metrics For Digital Marketing Dashboard
Brand/Category Performance Over Years
Horizontal Metrics For Dashboard (YTD FOR 2014 To 2017)
total_rev_year = df.groupby(['Year_of_Order'], as_index=False).Sales.sum()
#total_rev_year = total_rev_year[total_rev_year['Year_of_Order']== 2018]
total_rev_year
total_orders = df.groupby(['Year_of_Order'], as_index=False).Order_ID.nunique()
total_orders
total_category = df.Product_Name.nunique()
total_category
total_customers = df.Customer_ID.nunique()
total_customers
df['Year_of_Order'].value_counts()
Vertical Metrics For Dashboard
import plotly.graph_objects as go
df = df[df.Year_of_Order == 2014]
sales_per_category = df.groupby(['CategoryName'], as_index=False).Sales.sum()
sales_per_category = sales_per_category.sort_values(by=['Sales'], ascending=False)
sales_per_category.columns = ['Product Category', 'Sales_Revenue']
sales_per_category = sales_per_category[:20]
labels = sales_per_category['Product Category']
values = sales_per_category['Sales_Revenue']
# Use `hole` to create a donut-like pie chart
fig = go.Figure(data=[go.Pie(labels=labels, values=values, hole=.3)])
fig.show()
df = pd.read_csv('Sample store final.csv', error_bad_lines=False, engine='python')
df
Total Sales By Category For Individual Year
import plotly.graph_objects as go
df = df[df.Year_of_Order == 2015]
sales_per_category = df.groupby(['CategoryName'], as_index=False).Sales.sum()
sales_per_category = sales_per_category.sort_values(by=['Sales'], ascending=False)
sales_per_category.columns = ['Product Category', 'Sales_Revenue']
sales_per_category = sales_per_category[:20]
labels = sales_per_category['Product Category']
values = sales_per_category['Sales_Revenue']
# Use `hole` to create a donut-like pie chart
fig = go.Figure(data=[go.Pie(labels=labels, values=values, hole=.3)])
fig.show()
import plotly.graph_objects as go
df = df[df.Year_of_Order == 2017]
sales_per_category = df.groupby(['CategoryName'], as_index=False).Sales.sum()
sales_per_category = sales_per_category.sort_values(by=['Sales'], ascending=False)
sales_per_category.columns = ['Product Category', 'Sales_Revenue']
sales_per_category = sales_per_category[:20]
labels = sales_per_category['Product Category']
values = sales_per_category['Sales_Revenue']
# Use `hole` to create a donut-like pie chart
fig = go.Figure(data=[go.Pie(labels=labels, values=values, hole=.3)])
fig.show()
import plotly.graph_objects as go
df = df[df.Year_of_Order == 2016]
sales_per_category = df.groupby(['CategoryName'], as_index=False).Sales.sum()
sales_per_category = sales_per_category.sort_values(by=['Sales'], ascending=False)
sales_per_category.columns = ['Product Category', 'Sales Revenue']
sales_per_category = sales_per_category[:20]
labels = sales_per_category['Product Category']
values = sales_per_category['Sales Revenue']
# Use `hole` to create a donut-like pie chart
fig = go.Figure(data=[go.Pie(labels=labels, values=values, hole=.3)])
fig.show()
df = pd.read_csv('Sample store final.csv', error_bad_lines=False, engine='python')
df
total_rev_month = df.groupby(['Year_of_Order', 'Month_of_Order', 'CategoryName'], as_index=False).Sales.sum()
total_rev_month.columns = ['Sales Year','Sales Month','Product Category' , 'Sales Revenue']
total_rev_month
Category Sales Across Years
import plotly.express as px
import numpy as np
df = total_rev_month
fig = px.sunburst(df, path=['Sales Year', 'Product Category'], values='Sales Revenue',
color='Sales Revenue', hover_data=['Sales Revenue'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['Sales Revenue'], weights=df['Sales Revenue']))
fig.show()
total_profit_month = df.groupby(['Year_of_Order', 'Month_of_Order', 'CategoryName'], as_index=False).Profit.sum()
#total_rev_month = total_rev_month.sort_values(by=['order_purchase_year'], ascending=True)
total_profit_month.columns = ['Profit for Year','Sales Month','Product Category' , 'Profit']
total_profit_month
import plotly.express as px
import numpy as np
df = total_profit_month
fig = px.sunburst(df, path=['Profit for Year', 'Product Category'], values='Profit',
color='Profit', hover_data=['Profit'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['Profit'], weights=df['Profit']))
fig.show()
Let's Draw Insights From Our Weekday Sales For Each Individual Year
total_weekday_rev = df[df['Year_of_Order'] == 2014].groupby(['Day_of_order', 'CategoryName'], as_index=False).Sales.sum()
#total_rev_month = total_rev_month.sort_values(by=['order_purchase_year'], ascending=True)
total_weekday_rev.columns = ['Day_of_order','Product Category' , 'Sales Revenue']
total_weekday_rev
#Year 2014
labels = total_weekday_rev['Day_of_order']
values = total_weekday_rev['Sales Revenue']
# Use `hole` to create a donut-like pie chart
fig = go.Figure(data=[go.Pie(labels=labels, values=values, hole=.3)])
fig.show()
df = total_weekday_rev
fig = px.sunburst(df, path=['Day_of_order', 'Product Category'], values='Sales Revenue',
color='Sales Revenue', hover_data=['Product Category'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['Sales Revenue'], weights=df['Sales Revenue']))
fig.show()
total_weekday_rev = df[df['Year_of_Order'] == 2015].groupby(['Day_of_order', 'CategoryName'], as_index=False).Sales.sum()
#total_rev_month = total_rev_month.sort_values(by=['order_purchase_year'], ascending=True)
total_weekday_rev.columns = ['Day of Order','Product Category' , 'Sales Revenue']
total_weekday_rev
#Year 2015
labels = total_weekday_rev['Day of Order']
values = total_weekday_rev['Sales Revenue']
# Use `hole` to create a donut-like pie chart
fig = go.Figure(data=[go.Pie(labels=labels, values=values, hole=.3)])
fig.show()
df = total_weekday_rev
fig = px.sunburst(df, path=['Day of Order', 'Product Category'], values='Sales Revenue',
color='Sales Revenue', hover_data=['Product Category'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['Sales Revenue'], weights=df['Sales Revenue']))
fig.show()
total_weekday_rev = df[df['Year_of_Order'] == 2016].groupby(['Day_of_order', 'CategoryName'], as_index=False).Sales.sum()
#total_rev_month = total_rev_month.sort_values(by=['order_purchase_year'], ascending=True)
total_weekday_rev.columns = ['Day of Order','Product Category' , 'Sales Revenue']
total_weekday_rev
df = total_weekday_rev
fig = px.sunburst(df, path=['Day of Order', 'Product Category'], values='Sales Revenue',
color='Sales Revenue', hover_data=['Product Category'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['Sales Revenue'], weights=df['Sales Revenue']))
fig.show()
total_weekday_rev = df[df['Year_of_Order'] == 2017].groupby(['Day_of_order', 'CategoryName'], as_index=False).Sales.sum()
#total_rev_month = total_rev_month.sort_values(by=['order_purchase_year'], ascending=True)
total_weekday_rev.columns = ['Day of Order','Product Category' , 'Sales Revenue']
total_weekday_rev
#Year 2017
labels = total_weekday_rev['Day of Order']
values = total_weekday_rev['Sales Revenue']
# Use `hole` to create a donut-like pie chart
fig = go.Figure(data=[go.Pie(labels=labels, values=values, hole=.3)])
fig.show()
df = total_weekday_rev
fig = px.sunburst(df, path=['Day of Order', 'Product Category'], values='Sales Revenue',
color='Sales Revenue', hover_data=['Product Category'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['Sales Revenue'], weights=df['Sales Revenue']))
fig.show()
Category Activity Alongside Total Purchases
cat_activity = df[df['Year_of_Order'] == 2015].groupby(['CategoryName']).Order_ID.nunique()
#cat_activity = cat_activity.sort_values(['Activity'], ascending=True)
cat_activity = pd.DataFrame(cat_activity)
cat_activity.columns = [ 'Activity']
cat_activity = cat_activity.sort_values(by=['Activity'], ascending=False)
cat_activity
#Year 2015
fig = px.funnel_area(names=cat_activity.index,
values=cat_activity.Activity)
fig.show()
cat_activity = df[df['Year_of_Order'] == 2016].groupby(['CategoryName']).Order_ID.nunique()
#cat_activity = cat_activity.sort_values(['Activity'], ascending=True)
cat_activity = pd.DataFrame(cat_activity)
cat_activity.columns = [ 'Activity']
cat_activity = cat_activity.sort_values(by=['Activity'], ascending=False)
cat_activity
#Year 2016
fig = px.funnel_area(names=cat_activity.index,
values=cat_activity.Activity)
fig.show()
cat_activity = df[df['Year_of_Order'] == 2014].groupby(['CategoryName']).Order_ID.nunique()
#cat_activity = cat_activity.sort_values(['Activity'], ascending=True)
cat_activity = pd.DataFrame(cat_activity)
cat_activity.columns = [ 'Activity']
cat_activity = cat_activity.sort_values(by=['Activity'], ascending=False)
cat_activity
#Year 2014
fig = px.funnel_area(names=cat_activity.index,
values=cat_activity.Activity)
fig.show()
cat_activity = df[df['Year_of_Order'] == 2017].groupby(['CategoryName']).Order_ID.nunique()
#cat_activity = cat_activity.sort_values(['Activity'], ascending=True)
cat_activity = pd.DataFrame(cat_activity)
cat_activity.columns = [ 'Activity']
cat_activity = cat_activity.sort_values(by=['Activity'], ascending=False)
cat_activity
#Year 2014
fig = px.funnel_area(names=cat_activity.index,
values=cat_activity.Activity)
fig.show()
cat_activity = df[df['Year_of_Order'] == 2014].groupby(['Region']).Sales.nunique()
#cat_activity = cat_activity.sort_values(['Activity'], ascending=True)
cat_activity = pd.DataFrame(cat_activity)
cat_activity.columns = [ 'Activity']
cat_activity = cat_activity.sort_values(by=['Activity'], ascending=False)
cat_activity
cat_activity = df[df['Year_of_Order'] == 2015].groupby(['Region']).Sales.nunique()
#cat_activity = cat_activity.sort_values(['Activity'], ascending=True)
cat_activity = pd.DataFrame(cat_activity)
cat_activity.columns = [ 'Activity']
cat_activity = cat_activity.sort_values(by=['Activity'], ascending=False)
cat_activity
#Year 2015
fig = px.funnel_area(names=cat_activity.index,
values=cat_activity.Activity)
fig.show()
cat_activity = df[df['Year_of_Order'] == 2016].groupby(['Region']).Sales.nunique()
#cat_activity = cat_activity.sort_values(['Activity'], ascending=True)
cat_activity = pd.DataFrame(cat_activity)
cat_activity.columns = [ 'Activity']
cat_activity = cat_activity.sort_values(by=['Activity'], ascending=False)
cat_activity
#Year 2016
fig = px.funnel_area(names=cat_activity.index,
values=cat_activity.Activity)
fig.show()
cat_activity = df[df['Year_of_Order'] == 2017].groupby(['Region']).Sales.nunique()
#cat_activity = cat_activity.sort_values(['Activity'], ascending=True)
cat_activity = pd.DataFrame(cat_activity)
cat_activity.columns = [ 'Activity']
cat_activity = cat_activity.sort_values(by=['Activity'], ascending=False)
cat_activity
#Year 2017
fig = px.funnel_area(names=cat_activity.index,
values=cat_activity.Activity)
fig.show()
cat_activity = df[df['Year_of_Order'] == 2014].groupby(['State']).Order_ID.nunique()
#cat_activity = cat_activity.sort_values(['Activity'], ascending=True)
cat_activity = pd.DataFrame(cat_activity)
cat_activity.columns = [ 'Activity']
cat_activity = cat_activity.sort_values(by=['Activity'], ascending=False)
cat_activity
#Year 2014
fig = px.funnel_area(names=cat_activity.index,
values=cat_activity.Activity)
fig.show()
cat_activity = df[df['Year_of_Order'] == 2015].groupby(['State']).Order_ID.nunique()
#cat_activity = cat_activity.sort_values(['Activity'], ascending=True)
cat_activity = pd.DataFrame(cat_activity)
cat_activity.columns = [ 'Activity']
cat_activity = cat_activity.sort_values(by=['Activity'], ascending=False)
cat_activity
#Year 2015
fig = px.funnel_area(names=cat_activity.index,
values=cat_activity.Activity)
fig.show()
cat_activity = df[df['Year_of_Order'] == 2016].groupby(['State']).Order_ID.nunique()
#cat_activity = cat_activity.sort_values(['Activity'], ascending=True)
cat_activity = pd.DataFrame(cat_activity)
cat_activity.columns = [ 'Activity']
cat_activity = cat_activity.sort_values(by=['Activity'], ascending=False)
cat_activity
#Year 2016
fig = px.funnel_area(names=cat_activity.index,
values=cat_activity.Activity)
fig.show()
cat_activity = df[df['Year_of_Order'] == 2017].groupby(['State']).Order_ID.nunique()
#cat_activity = cat_activity.sort_values(['Activity'], ascending=True)
cat_activity = pd.DataFrame(cat_activity)
cat_activity.columns = [ 'Activity']
cat_activity = cat_activity.sort_values(by=['Activity'], ascending=False)
cat_activity
#Year 2016
fig = px.funnel_area(names=cat_activity.index,
values=cat_activity.Activity)
fig.show()
cat_activity = df[df['Year_of_Order'] == 2014].groupby(['City']).Order_ID.nunique()
#cat_activity = cat_activity.sort_values(['Activity'], ascending=True)
cat_activity = pd.DataFrame(cat_activity)
cat_activity.columns = [ 'Activity']
cat_activity = cat_activity.sort_values(by=['Activity'], ascending=False)
cat_activity
total_year_rev = df[df['Year_of_Order'] == 2014].groupby(['Month_of_Order', 'CategoryName'], as_index=False).Sales.sum()
#total_rev_month = total_rev_month.sort_values(by=['order_purchase_year'], ascending=True)
total_year_rev.columns = ['Month_of_order','CategoryName' , 'Sales Revenue']
total_year_rev
#Year 2014
df = total_year_rev
fig = px.sunburst(df, path=['Sales Revenue', 'CategoryName'], values='Sales Revenue',
color='Sales Revenue', hover_data=['CategoryName'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['Sales Revenue'], weights=df['Sales Revenue']))
fig.show()
total_year_rev = df[df['Year_of_Order'] == 2015].groupby(['Month_of_Order', 'CategoryName'], as_index=False).Sales.sum()
#total_rev_month = total_rev_month.sort_values(by=['order_purchase_year'], ascending=True)
total_year_rev.columns = ['Month_of_order','CategoryName' , 'Sales Revenue']
total_year_rev
Let's Take a Glimpse at Our Sales Revenue For All Product Category For each Individual Year
#Year 2015
df = total_year_rev
fig = px.sunburst(df, path=['Sales Revenue', 'CategoryName'], values='Sales Revenue',
color='Sales Revenue', hover_data=['CategoryName'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['Sales Revenue'], weights=df['Sales Revenue']))
fig.show()
total_year_rev = df[df['Year_of_Order'] == 2016].groupby(['Month_of_Order', 'CategoryName'], as_index=False).Sales.sum()
#total_rev_month = total_rev_month.sort_values(by=['order_purchase_year'], ascending=True)
total_year_rev.columns = ['Month_of_order','CategoryName' , 'Sales Revenue']
total_year_rev
#Year 2016
df = total_year_rev
fig = px.sunburst(df, path=['Sales Revenue', 'CategoryName'], values='Sales Revenue',
color='Sales Revenue', hover_data=['CategoryName'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['Sales Revenue'], weights=df['Sales Revenue']))
fig.show()
total_year_rev = df[df['Year_of_Order'] == 2017].groupby(['Month_of_Order', 'CategoryName'], as_index=False).Sales.sum()
#total_rev_month = total_rev_month.sort_values(by=['order_purchase_year'], ascending=True)
total_year_rev.columns = ['Month_of_order','CategoryName' , 'Sales Revenue']
total_year_rev
#Year 2017
df = total_rev_hour
fig = px.sunburst(df, path=['Sales Revenue', 'CategoryName'], values='Sales Revenue',
color='Sales Revenue', hover_data=['CategoryName'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['Sales Revenue'], weights=df['Sales Revenue']))
fig.show()
Take a Peep at Profits Made For Each Individual Year
total_year_profit = df[df['Year_of_Order'] == 2014].groupby(['Month_of_Order', 'CategoryName'], as_index=False).Profit.sum()
total_year_profit.columns = ['Month_of_order','CategoryName' , 'Profit']
total_year_profit
total_year_profit = df[df['Year_of_Order'] == 2014].groupby(['Month_of_Order', 'CategoryName'], as_index=False).Profit.sum()
total_year_profit.columns = ['Month_of_order','CategoryName' , 'Profit']
total_year_profit
#Year 2014
df = total_year_profit
fig = px.sunburst(df, path=['Profit', 'CategoryName'], values='Profit',
color='Profit', hover_data=['CategoryName'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['Profit'], weights=df['Profit']))
fig.show()
total_year_profit = df[df['Year_of_Order'] == 2015].groupby(['Month_of_Order', 'CategoryName'], as_index=False).Profit.sum()
total_year_profit.columns = ['Month_of_order','CategoryName' , 'Profit']
total_year_profit
#Year 2015
df = total_year_profit
fig = px.sunburst(df, path=['Profit', 'CategoryName'], values='Profit',
color='Profit', hover_data=['CategoryName'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['Profit'], weights=df['Profit']))
fig.show()
total_year_profit = df[df['Year_of_Order'] == 2015].groupby(['Month_of_Order', 'CategoryName'], as_index=False).Profit.sum()
total_year_profit.columns = ['Month_of_order','CategoryName' , 'Profit']
total_year_profit
#Year 2015
df = total_year_profit
fig = px.sunburst(df, path=['Profit', 'CategoryName'], values='Profit',
color='Profit', hover_data=['CategoryName'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['Profit'], weights=df['Profit']))
fig.show()
total_year_profit = df[df['Year_of_Order'] == 2016].groupby(['Month_of_Order', 'CategoryName'], as_index=False).Profit.sum()
total_year_profit.columns = ['Month_of_order','CategoryName' , 'Profit']
total_year_profit
#Year 2016
df = total_year_profit
fig = px.sunburst(df, path=['Profit', 'CategoryName'], values='Profit',
color='Profit', hover_data=['CategoryName'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['Profit'], weights=df['Profit']))
fig.show()
total_year_profit = df[df['Year_of_Order'] == 2017].groupby(['Month_of_Order', 'CategoryName'], as_index=False).Profit.sum()
total_year_profit.columns = ['Month_of_order','CategoryName' , 'Profit']
total_year_profit
#Year 2017
df = total_year_profit
fig = px.sunburst(df, path=['Profit', 'CategoryName'], values='Profit',
color='Profit', hover_data=['CategoryName'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['Profit'], weights=df['Profit']))
fig.show()